package com.xiaoxu.scala_base.code

/**
  * 循环表达式
  * author: zhangXu
  * createTime: 2018-12-07 20:00
  **/
object Loop {
  def main(args: Array[String]): Unit = {
    1 to 10
    1.to(10)
    Range(1, 10)
    Range(1, 10, 2)
    1 until 10
    1.until(10)

    print("to ")
    for (i <- 1 to 10) {
      print(i)
    }
    println("to  i%2 == 0")
    for (i <- 1 to 10 if i % 2 == 0) {
      print(i)
    }

    println()
    print("until ")
    for (i <- 1 until 10) {
      println(i)
    }

    val nums = Array("1", "2", "3", "4")
    for (num <- nums) {
      println(num)
    }

    // n 其实就是nums里面的每个元素
    // ==>  就是将左边的n作为参数作用上一个函数，函数开始执行
    nums.foreach(n => println(n))
    nums.foreach(println)

    var i = 10
    while (i > 0) {
      println(i)
      i -= 1
    }



  }


}
